package com.jiankangjin.httpclient;

import java.io.InputStream;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.Map.Entry;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * @author liuzy
 * @date 2014年8月10日 上午12:05:44
 */
public class PropertiesLoader {
	private static final transient Log log = LogFactory.getLog(PropertiesLoader.class);

	private PropertiesLoader() {
	}
	
	/**
	 * loade 加载HttpClient.properties文件到propertiesMap中
	 */
	public static Map<String, String> loade() {
		InputStream inputStream = PropertiesLoader.class.getClassLoader().getResourceAsStream("HttpClient.properties");
		Properties pops = new Properties();
		try {
			pops.load(inputStream);
			Set<Entry<Object, Object>> set = pops.entrySet();
			Iterator<Map.Entry<Object, Object>> it = set.iterator();
			String key = null;
			String value = null;
			Map<String, String> propertiesMap = new HashMap<String, String>();
			while (it.hasNext()) {
				Entry<Object, Object> entry = it.next();
				key = String.valueOf(entry.getKey());
				value = String.valueOf(entry.getValue());
				key = key == null ? key : key.trim();
				value = value == null ? value : value.trim();
				propertiesMap.put(key, value);
			}
			return propertiesMap;
		} catch (Exception e) {
			log.error("加载HttpClient.properties失败");
			return null;
		}
	}
}
